<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // reduce数组求和
        var  arr = [1,2,3];
        // 需求求取数组的和  6
        // reduce第一个参数是回调函数 第二个参数是初始值0
        var number = arr.reduce((pre,item,index)=>{
            console.log(pre);//初始值
            console.log(item);//数组当中的每一项
            console.log(index);//下标
            return pre + item
        },0);
        console.log(number);
    </script>
</body>
</html>